/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package nominalitzacions.persistance;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import nominalitzacions.domain.UrlDomainController;

/**
 *
 * @author daniel.camacho.rodriguez
 */
public class PasswordDataManager {

    private File passwordFile;
    private UrlDomainController UDC;

    public PasswordDataManager(UrlDomainController UDC) {
        this.UDC = UDC;
        passwordFile = new File(UDC.getSecurity()+"AquiNoHiHaRes");
    }

    public void writePassword(String pass) throws IOException {
        if(passwordFile.exists()) passwordFile.delete();
        passwordFile.createNewFile();

        FileWriter flw = new FileWriter(passwordFile);
        BufferedWriter bw = new BufferedWriter(flw);
        // Encriptamos?
        bw.write(pass);
        bw.newLine();
        bw.close();

    }

    private String encript(String s){
        return "iep";
    }

    public String readPassword() throws FileNotFoundException {
        Scanner sc = new Scanner(passwordFile);
        String pass = new String();
        if (sc.hasNextLine() ) pass = sc.nextLine();
        sc.close();
        // Desencriptamos?
        return pass;
    }

}
